package com.spic.system.api.factory;

import com.spic.common.core.domain.R;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.system.api.RemoteUserService;
import com.spic.system.api.domain.SysDept;
import com.spic.system.api.domain.SysRole;
import com.spic.system.api.domain.SysUser;
import com.spic.system.api.model.LoginUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;
import java.util.Map;

/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<LoginUser> getUserInfo(String username, String source)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUser sysUser, String source)
            {
                return R.fail("注册用户失败:" + throwable.getMessage());
            }

            @Override
            public Object treeselectList(@RequestBody SysDept dept) {
                return R.fail("获取部门树服务失败"+throwable.getMessage());
            }
            @Override
            public R<SysDept> lists(Long deptId) {
                return R.fail("获取部门列表失败"+throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getSysUserByDeptIds(Long[] deptIds)
            {
                 return R.fail("获取用户列表失败");
            }

            @Override
            public R<Map<Long,String>> map() {
                return R.fail("获取部门map失败"+throwable.getMessage());
            }

            @Override
            public R<List<Map<String,Object>>> selectAdminByRoleAndDept(Map<String, Object> map) {
                return R.fail("获取用户失败"+throwable.getMessage());
            }

            @Override
            public R<String> getCode(String codeName) {
                return R.fail("获取流水号失败"+throwable.getMessage());
            }

            @Override
            public R<List<Map<String, Object>>> getPostUser()
            {
                return R.fail("获取用户岗位失败"+throwable.getMessage());
            }

            @Override
            public R<Map<Long, String>> getCacheByUserId()
            {
                return R.fail("获取用户缓存失败");
            }
            @Override
            public R<SysUser> getUserById(Long userId)
            {
                return R.fail("获取用户列表失败"+throwable.getMessage());
            }

            @Override
            public R<List<SysUser>> getSysUserByDeptId(Long deptId) {
                return R.fail("获取用户列表失败"+throwable.getMessage());
            }


            @Override
            public R<SysRole> getRoleById(Long roleId)
            {
                return R.fail("获取岗位列表失败"+throwable.getMessage());
            }
            @Override
            public R<SysUser> userInfo(SysUser sysUser)
            {
                return R.fail("获取用户列表失败"+throwable.getMessage());
            }
            @Override
            public R<SysUser> getWzUserId(String deptId) {return R.fail("获取违章管理员失败"+throwable.getMessage()); }
            @Override
            public R<String> selectConfigByKey(String configKey)
            {
                return R.fail("获取参数失败:" + throwable.getMessage());
            }
            @Override
            public R<AjaxResult> updateCid(SysUser user) {
                return R.fail("获取参数失败:"+throwable.getMessage());
            }

            @Override
            public R<SysUser> addUser(SysUser sysUser) {
                return R.fail("添加用户失败");
            }

            @Override
            public R<Long[]> getUserListByParentId(Long parentDeptId)
            {
                return R.fail("添加用户失败");
            }

            @Override
            public R<Long[]> setStateHidden()
            {
                return R.fail("更新公示公告定时任务失败:" + throwable.getMessage());
            }

            @Override
            public R<AjaxResult> syncuser2all() {
                return R.fail("数据治理同步用户定时任务失败:" + throwable.getMessage());
            }

            @Override
            public R<AjaxResult> filterUserDirtyData() {
                return R.fail("数据治理筛选用户脏数据定时任务失败:" + throwable.getMessage());
            }
        };

    }
}
